package com.spring.annotation.MultiInjection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangyg on 2017/1/9.
 */
@Component
public class BeanInvoker {
	@Autowired
	private List<BeanInterface> beans;
	@Autowired
	private Map<String, BeanInterface> map;
	@Qualifier("beanImplTwo")
	@Autowired
	private BeanInterface beanInterface;

	public void getAllBeans() {
		if (beans != null && beans.size() != 0) {
			for (BeanInterface bean : beans) {
				System.out.println(bean.getClass().getName());
			}
		} else {
			System.out.println("List<BeanInterface> beans is null");
		}
	}

	public void getAllMaps() {
		if (map != null && map.size() != 0) {
			for (Map.Entry<String, BeanInterface> entry : map.entrySet()) {
				System.out.println(entry.getKey() + "    " + entry.getValue().getClass().getName());
			}
		} else {
			System.out.println("Map<String,BeanInterface> map is null");
		}

	}

	public void showWhichBean(){
		System.out.println("beanInterface :"+beanInterface.getClass().getName());
	}

/*	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("a", "b");
		map.put("c", "d");
		map.put("e", "f");
		//两种方式，取key-value
		System.out.println("方式一：");
		for (Map.Entry<String, String> entry : map.entrySet()) {
			System.out.println(entry.getKey() + ":" + entry.getValue());
		}
		System.out.println("方式二：");
		for (String key : map.keySet()) {
			System.out.println(key + ":" + map.get(key));
		}

	}*/

}
